$(function () {
    // 获取消费记录
    var loading = weui.loading('loading', {
        className: 'custom-classname'
    });
    var result = Model.user.getBalance();
    if (!sessionStorage.getItem('hmdj_stopError')) {
        sessionStorage.setItem('hmdj_stopError', true);
    } else {
        if (result.code) {
            Common.fn.formatOutput(result);
            loading.hide();
            return false;
        }
    }
    // 获取红米金额
    var redRice = result.data[0].redRice;
    redRice == null ? redRice = 0 : redRice = redRice;
    $('.topPrice').text(redRice);
    $('.balance-num').text(result.data[0].balance);
    for (var i = 0; i < result.data[0].history.length; i++) {
        var item = '<div class="weui-cells shop-item"><div class="weui-cell"><div class="weui-cell__bd"><p>' + result.data[0].history[i].content + '</p><p>' + result.data[0].history[i].time + '</p></div><div class="weui-cell__ft"><h2>' + result.data[0].history[i].change + '</h2></div></div></div>'
        $('.shop-items').append(item);
    }
    loading.hide();
});

// 提现按钮
$(document).on('click', '.withdraw-btn', function () {
    // 判断金额是否大于0
    if (parseInt($('.balance-num').text()) <= 0) {
        weui.alert('余额不足，无法提现');
        return false;
    }
    location.href = 'encash.html';
});